package com.sy.common.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class BeanOfMap {
    public static Map bom(Object data){
        Map map = new HashMap();
        Field[] field = data.getClass().getDeclaredFields();
        for (Field f : field){
            f.setAccessible(true);
            Object value = null;
            try {
                value = f.get(data);
                map.put(f.getName(),value);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
        return map;
    }
    public static Integer getIntValue(Map map,String key){
        if (null==map||!map.containsKey(key))
            return null;
        //取值
        Object obj = map.get(key);
        if (null==obj)
            return null;
        return Integer.parseInt(obj.toString());
    }
    public static String getStringValue(Map map,String key){
        if (null==map||!map.containsKey(key))
            return null;
        //取值
        Object obj = map.get(key);
        if (null==obj)
            return null;
        return obj.toString();
    }
}
